import Axios from './axios-config';
import { BASE_API } from '@/services/constant';

interface OtherConfig {
  method: 'POST' | 'GET';
  contentType?: string;
  data?: any;
  params?: any;
  headers?: any;
}
const request = (url: string, otherConfig: OtherConfig) => {
  const config = {
    url,
    ...otherConfig
  };
  return Axios(config);
};
export const requestOrigin = (url: string, otherConfig: OtherConfig) => {
  const config = {
    url: BASE_API + url,
    ...otherConfig
  };
  return Axios(config);
};

export const extend = (otherconfig: any) => {
  return (url: string, config: OtherConfig) => {
    let newUrl = url;
    if (otherconfig.prefix) {
      newUrl = otherconfig.prefix + url;
    }
    return request(newUrl, config);
  };
};

export default request;